#!/bin/sh
# PD_CLUSTER=tidb1:4000,tidb1:4000,tidb1:4000
for host in `echo ${PD_CLUSTER} | sed "s/,/\n/g"`
do
    HO="${HO}|    server ${host} max_fails=3 fail_timeout=30s;"
done
LIST=`echo ${HO:1} | sed 's/|/\n/g'`
cat > /etc/nginx/conf.d/stream/tidb.conf << EOF
upstream tidb {
${LIST}
}
server {
    listen 3306;
    proxy_pass tidb;
}
EOF

# run nginx
exec nginx
